package com.cloudptt.wp.ui.call;

import android.content.Context;
import android.os.Handler;
import android.util.AttributeSet;
import android.view.SurfaceView;

public class AutoHideSurfaceView extends SurfaceView {
    private Handler mHandler = new Handler();
    private Runnable mHideRunnable = () -> hideControls();
    private boolean mIsHidden = false;
    private UiControl uiControl = null;

    public AutoHideSurfaceView(Context context) {
        super(context);
        init();
    }
    public AutoHideSurfaceView(Context context, AttributeSet attrs)
    {
        super(context,attrs);
        init();
    }
    public AutoHideSurfaceView(Context context, AttributeSet attrs, int defStyleAttr)
    {
        super(context,attrs,defStyleAttr);
        init();
    }


    public void setUiControl(UiControl uiControl)
    {
        this.uiControl = uiControl;
    }


    public void init() {
        startHideTimer();
    }

    private void hideControls() {
        if(uiControl != null)
        {
            uiControl.hideControlUi(false);
        }
    }

    private void startHideTimer() {
        mHandler.removeCallbacks(mHideRunnable);
        mHandler.postDelayed(mHideRunnable, 10000); // 10秒延迟
    }

    @Override
    protected void onDetachedFromWindow() {
        mHandler.removeCallbacks(mHideRunnable);
        super.onDetachedFromWindow();
    }
}

